package code.class1;

/**
 * https://leetcode.cn/problems/percentage-of-letter-in-string/description/
 * 字母在字符串中的百分比
 */
public class Code17_percentageLetter {
    public static void main(String[] args) {
        String str = "foobar";
        char letter = 'o';
        int i = percentageLetter(str, letter);
        System.out.println("i = " + i);
    }

    public static int percentageLetter(String s, char letter) {
        int total = 0;
        for (char c : s.toCharArray()) {
            if (c == letter) total++;
        }
        return (int) ((total + .0) / s.length() * 100);
    }
}
